package com.example.yunhailutong.zhongtan.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.yunhailutong.zhongtan.R;
import com.example.yunhailutong.zhongtan.entity.CsfcEntity.DataBean.CsfcInfoBean;

import java.util.List;

public class CsfcListViewAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private List<CsfcInfoBean> informationBeanList;
    public CsfcListViewAdapter(Context context, List<CsfcInfoBean> dataList) {
        mInflater = LayoutInflater.from(context);
        informationBeanList = dataList;
    }

    @Override
    public int getCount() {
        return informationBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return informationBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.fragment_main_third_part_list_item, null);
            viewHolder = new ViewHolder();
            viewHolder.third_part_list_item_image = (ImageView) convertView.findViewById(R.id.third_part_list_view_item_iv);
            viewHolder.third_part_list_item_title = (TextView) convertView.findViewById(R.id.third_part_list_view_item_title);
            viewHolder.third_part_list_item_time = (TextView) convertView.findViewById(R.id.third_part_list_view_item_time);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        //在此处对viewholder变量赋值
        viewHolder.third_part_list_item_title.setText(informationBeanList.get(position).getIm_title());
        viewHolder.third_part_list_item_time.setText(informationBeanList.get(position).getIm_addTime());
        Glide.with(convertView.getContext()).load(informationBeanList.get(position).getIm_imgPath()).into(viewHolder.third_part_list_item_image);
        return convertView;
    }

    private class ViewHolder {
        ImageView third_part_list_item_image;
        TextView third_part_list_item_title;
        TextView third_part_list_item_time;
    }
}
